package com.longway.core.ext.excel.formats;

import java.text.SimpleDateFormat;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;

public class DefaultExcelFormats implements ExcelFormats{
	@Override
	public void setHeader(Workbook wb,Cell cell) {
		CellStyle style = wb.createCellStyle();
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBottomBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderRight(BorderStyle.THIN);
        style.setRightBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
		style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        cell.setCellStyle(style);
	}

	@Override
	public void setTitle(Cell cell) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void setSummaryCell(Cell cell) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void setNumberCell(Workbook wb,Cell cell) {
		setNumberCell2(wb,cell);
	}
	
	public void setNumberCell0(Workbook wb,Cell cell) {
		CellStyle style = wb.createCellStyle();
		DataFormat df = wb.createDataFormat(); // 此处设置数据格式
		style.setDataFormat(df.getFormat("#,#0"));//数据格式只显示整数
	}
	
	public void setNumberCell2(Workbook wb,Cell cell) {
		CellStyle style = wb.createCellStyle();
		DataFormat df = wb.createDataFormat(); // 此处设置数据格式
		style.setDataFormat(df.getFormat("#,##0.00"));//保留两位小数点
	}

	@Override
	public PaperSize setpapersize() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setDateFormatCell(Cell cell) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void setStringCell(Workbook wb,Cell cell) {
		CellStyle style = wb.createCellStyle();
		style.setAlignment(HorizontalAlignment.LEFT);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBottomBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderRight(BorderStyle.THIN);
        style.setRightBorderColor(HSSFColorPredefined.BLACK.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(HSSFColorPredefined.BLACK.getIndex());
        cell.setCellStyle(style);
		
	}
	@Override
	public SimpleDateFormat getDateFormat() {
		return new SimpleDateFormat("yyyy-MM-dd");
	}
}
  
